package com.itheima.controller;

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> cheng
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
<<<<<<< HEAD
=======
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;
import java.util.Map;
>>>>>>> zhao
=======
>>>>>>> cheng

@RestController
@RequestMapping("user")
public class UserController {

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> cheng
    @RequestMapping("getUsername")
    public Result getUsername(Principal principal){

        try {
            String name = principal.getName();
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS,name);
<<<<<<< HEAD
=======
    @Reference
    private UserService userService;

    @RequestMapping("getUsername")
    public Result getUsername(Principal principal) {

        try {
            String name = principal.getName();
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS, name);
>>>>>>> zhao
=======
>>>>>>> cheng
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }

    }
<<<<<<< HEAD
<<<<<<< HEAD
=======

    @RequestMapping("findAllUser")
    public Result findAllUser(@RequestBody QueryPageBean queryPageBean) {

        try {
            PageResult userList = userService.findAllUser(queryPageBean.getCurrentPage(), queryPageBean.getPageSize(), queryPageBean.getQueryString());
            return new Result(true, "查询用户列表成功", userList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询用户列表失败");
        }
    }

    @RequestMapping("edit")
    public Result edit(@RequestParam("roleIds") Integer[] roleIds, @RequestBody User user) {

        try {
            userService.edit(roleIds, user);
            return new Result(true, "添加用户列表成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加用户列表失败");
        }
    }

    @RequestMapping("deleteUserByUserId")
    public Result deleteUserByUserId(@RequestParam("id") Integer id) {

        try {
            userService.deleteUserByUserId(id);
            return new Result(true, "删除用户成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "删除用户失败");
        }
    }

    @RequestMapping("addUser")
    public Result addUser(@RequestParam("roleIds") Integer[] roleIds, @RequestBody User user) {


        try {
            userService.addUser(roleIds, user);
            return new Result(true, "添加用户成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加用户失败");
        }
    }



>>>>>>> zhao
=======
>>>>>>> cheng
}
